package com.offcn.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

//对象转json工具类
public class ObjectJsonUtil {
    public static void objOrJson(Object object, HttpServletResponse response) throws IOException {
		ObjectMapper objectMapper=new ObjectMapper();
        PrintWriter writer = response.getWriter();
        String json= null;
        try {
            json = objectMapper.writeValueAsString(object);
        } catch (Exception e) {
            e.printStackTrace();
        }
        writer.print(json);
    }
}
